import React from "react";
import GoodNode from "../../../Component/Good";
import SortTabItem from "../../../Component/SortTabItem";
// import './index.css';
import { Radio } from 'antd';
import UserCheck from "../../../utils/UserCheck";
import URL from "../../../Server/URL";
import MessageUtil from "../../../utils/MessageUtil";
import ShopServer from "../../../Server/Trade/ShopServer";
import { Button } from 'antd';
import TransactionServer from "../../../Server/Trade/TransactionServer";

export default class extends React.Component{
    
    constructor(props){
        super();
        this.state={
            allFlag:false,
            creFlag:false,
            priceFlag:false,
            bPriceFlag:false,
            usertype:0, //0买家 1卖家
            orderType:1, //0二手 1租赁
            orderStatus:"", //订单状态 0 待支付 1已支付待发货 2已发货 3派验机 4已收货 5已取消
            goods:[],
            cashDepositStatus:0,
            insuranceStatus:0,
            aerocraftStatus:0,
            page:1
        }

        this.Gen();
    }
    componentWillUnmount(){
        MessageUtil.ShowSuspention("");
    }
    componentWillMount(){
        MessageUtil.ShowSuspention("TradeDistribure");
    }
    Gen(){
        let goods=[];
        TransactionServer.TransactionSelectSecondHandPayList(
            this.state.cashDepositStatus,
            this.state.insuranceStatus,
            this.state.aerocraftStatus,
            this.state.page
        )
        .then(response=>{
            console.log(response)
            response.data.forEach(i => {
                let timeStr="";
                let stateInfo="";
                let mainPic="";
                let brand="";//品牌
                let type="";//类型
                let title="";//标题
                let price="";
                let insurence=false;
                let ca=false;
                // let shopStateTitle="";
                let time=new Date();
                let shopStates=["待支付", "已支付待发货", "已发货", "派验机", "已收货", "已取消"];
                let rightButton="";
                let desc="";
                let id="";
                switch(i.shopType){
                    case "0": //二手无人机
                        let data=i.aircraft;
                        brand=data.aerocraftBrand;
                        type=data.aerocraftType;
                        mainPic=data.aerocraftImgUrl;
                        title=data.title;
                        price=data.price;
                        ca=data.cashDeposit>0;
                        insurence=data.insuranceStatus===0;
                        desc=data.shopDescribe;
                        // let order=i.SecondHandOrder;
                        // shopStateTitle=shopStates[order.status];
                        // let orderTime=new Date(order.placeOrderTime);
                        // time=orderTime;
                        id=data.id;

                        // //计算功能按钮
                        // switch(order.status){
                        //     case "0":
                        //         rightButton=<span><Button type={"primary"} shape="round" style={{width:"8rem"}}>付款</Button></span>
                        //         break;
                        //     case "1":
                        //         rightButton=<span><Button type={"primary"} shape="round" style={{width:"8rem"}}>提醒发货</Button></span>
                        //         break;
                        //     case "2":
                        //         rightButton=
                        //             <span>
                        //                 <Button type={""} shape="round" style={{width:"8rem", border:"solid #5393eb 1px"}}>查看物流</Button>
                        //                 <Button type={"primary"} shape="round" style={{width:"8rem",marginLeft:"0.5rem"}}>确认发货</Button>
                        //             </span>
                        //         break;
                        //     case "3":
                        //         rightButton=
                        //         <span>
                        //                 <Button type={"primary"} shape="round" style={{width:"8rem",marginLeft:"0.5rem"}}>查看报告</Button>
                        //         </span>
                        //         break;
                        //     case "4":
                        //         rightButton=
                        //             <span>
                        //                 <Button type={""} shape="round" style={{width:"8rem",color:"#5393eb", border:"solid #5393eb 1px"}}>查看物流</Button>
                        //                 <Button type={"primary"} shape="round" style={{width:"8rem",marginLeft:"0.5rem"}}>返货</Button>
                        //             </span>
                        //         break;
                        //     case "5":
                        //         rightButton="";
                        //         break;
                        //     default:
                        //         break;
                        // }
                        // break;
                    case "1"://二手配件
                        break;
                    case "2"://租赁
                        break;
                    default:
                        break;
                }
                let badge=[];
                if(insurence){
                    badge.push(<img alt="Insurance" src="/assets/Good/Insurance.png"/>);
                }
                if(ca){
                    badge.push(<img alt="GuaranteeMoney" src="/assets/Good/GuaranteeMoney.png"/>)
                }

                goods.push(
                    <a key={id} href={"/trade/secondHandDetail/"+id+"/"+i.shopType} alt="good">
                        <GoodNode header={ URL.GetURL(i.userHead)}
                        key={i}
                        insurance={insurence}
                        guaranteeMoney={ca}
                        order={false}
                        modify={false}
                        heart={true} 
                        bag={true} delete={false} 
                        name={title}
                        time={timeStr}
                        desc={` ${desc}`}
                        state={stateInfo}
                        price={price}
                        />
                        </a>
                )
            });

            this.setState({
                goods
            },()=>{
                MessageUtil.ChangeHeight();
            })
        });
    }
    ClickFlag(orderSelectType,orderType){
        let allFlag=true;
        let nearFlag=true;
        let priceFlag=true;
        let timeFlag=true;
        let stateFlag=true;
        // console.log(orderSelectType)
        // console.log(orderType)

        let currentSelectType=0;
        switch(orderSelectType){
            case 0:
                allFlag=false;
                currentSelectType=0;
                break;
            case 1:
                nearFlag=false;
                break;
            case 2:
                priceFlag=false;
                if(orderType===0){
                    currentSelectType=2;
                }
                if(orderType===1){
                    currentSelectType=3;
                }
                break;
            case 3:
                timeFlag=false;
                if(orderType===0){
                    currentSelectType=1;
                }
                if(orderType===1){
                    currentSelectType=4;
                }
                break;
            case 4:
                stateFlag=false;
                break;
            default:
                break;
        }
        // console.log(orderType)
        // console.log(currentSelectType);
        this.setState({
            allFlag,
            nearFlag,
            priceFlag,
            timeFlag,
            stateFlag,
            currentSelectType:currentSelectType,
        },()=>{
            this.Gen();
        });
    }
    render(){
        return(
            <div className="Courseware_Body">
                <div className="Home_Sort">
                    <span className="Home_Sort_Item">
                        <SortTabItem clear={this.state.allFlag} 
                        title="综合" Change={this.ClickFlag.bind(this)} orderSelectType={0}/>
                    </span>
                    <span className="Home_Sort_Item">
                        <SortTabItem clear={this.state.creFlag} 
                        title="信用" Change={this.ClickFlag.bind(this)} orderSelectType={1}/>
                        </span>
                    <span className="Home_Sort_Item">
                        <SortTabItem clear={this.state.priceFlag} 
                        title="价格" Change={this.ClickFlag.bind(this)} orderSelectType={2}/>
                        </span>
                    <span className="Home_Sort_Item">
                        <SortTabItem clear={this.state.bPriceFlag} 
                        title="可议价" Change={this.ClickFlag.bind(this)} orderSelectType={3}/>
                        </span>
                </div>
                <div>
                    <Radio onClick={e=>this.setState({
                        insuranceStatus:this.state.insuranceStatus===0?1:0,
                    })}>保险</Radio>
                    <Radio onClick={e=>this.setState({
                        cashDepositStatus:this.state.cashDepositStatus===0?1:0,
                    })}>保证金</Radio>
                    <Radio onClick={e=>this.setState({
                        aerocraftStatus:this.state.aerocraftStatus===0?1:0,
                    })}>fly派认证</Radio>
                </div>
                <div>
                    {this.state.goods}
                </div>
            </div>
        )
    }
}